#ifndef	_HOOK_ALL_H
#define	_HOOK_ALL_H


#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>

#define EXPORT_SYMBOL(sym)

#define container_of(ptr, type, member) \
    (type *)((char *)(ptr) - (char *) &((type *)0)->member)

#define __init
#define __exit

typedef uint64_t cycles_t;

static inline cycles_t get_cycles(void) {
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts);  // 获取系统实时时间
    //printf("Seconds: %ld, Nanoseconds: %ld\n", ts.tv_sec, ts.tv_nsec);
    
    // 转换为微秒
    long microseconds = ts.tv_sec * 1000000 + ts.tv_nsec / 1000;

    return (cycles_t)microseconds;
}

#define printk printf
#define KERN_ALERT "[ALERT] "
#define KERN_ERR "[ERR] "



// 仿照内核的 rnd_state 结构
struct rnd_state {
    uint32_t s1, s2, s3, s4;
};

// 伪随机数生成（类似 prandom_u32_state）
static inline uint32_t prandom_u32_state(struct rnd_state *state) {
    uint32_t t = state->s1 ^ (state->s1 << 11);
    state->s1 = state->s2;
    state->s2 = state->s3;
    state->s3 = state->s4;
    state->s4 = (state->s4 ^ (state->s4 >> 19)) ^ (t ^ (t >> 8));
    return state->s4;
}

// 初始化种子（类似 prandom_seed_state）
static inline void prandom_seed_state(struct rnd_state *state, uint32_t seed) {
    state->s1 = 0x6C078965 * (seed ^ (seed >> 30)) + 1;
    state->s2 = 0x6C078965 * (state->s1 ^ (state->s1 >> 30)) + 2;
    state->s3 = 0x6C078965 * (state->s2 ^ (state->s2 >> 30)) + 3;
    state->s4 = 0x6C078965 * (state->s3 ^ (state->s3 >> 30)) + 4;
}

#define __force

#define WARN_ON_ONCE
#define WRITE_ONCE(x, val) \
	(x) = (val)				\


#define div_u64(x, y)  ((x) / (y))

/* TODO */
#define rcu_assign_pointer(ptr, val) ((ptr)) = (val)

#define unlikely(x) (x)

#endif

